﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>驰骋工作流</title>
    <!-- 于庆海 -->
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../Comm/Gener.js"></script>
    <script type="text/javascript" language="javascript">
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");
        });

        //初始化数据.
        function InitPage() {

            //设定枚举值下拉框.
            GenerBindEnumKey("DDL_BillFileType", "BillFileType", 0);
            GenerBindEnumKey("DDL_BillOpenModel", "BillOpenModel", 0);

            var nodeID = GetQueryString("FK_Node");
            var ens = new Entities("BP.WF.Template.BillTemplates");
            ens.Retrieve("NodeID", nodeID);

            var fk_BillTemplate = GetQueryString("FK_BillTemplate");
            var currBill = null;

            //生成列表.
            //增加处理.
            for (var i = 0; i < ens.length; i++) {

                var en = ens[i];

                if (fk_BillTemplate == en.No) {
                    currBill = en;
                }

                var newRow = "";
                newRow = "<tr ><td class=Idx>" + i + "</td>";
                newRow += "<td>" + en.No + "</td>";
                newRow += "<td>" + en.Name + "</td>";
                newRow += "<td>" + en.QRModelText + "</td>";

                newRow += "<td><a href='" + Handler + "?DoType=Bill_Download&No=" + en.No + "'>" + en.TempFilePath + "</td>";

                newRow += "<td>";
                newRow += "<a href=\"javascript:Delete('" + en.No + "')\"><img src='" + basePath + "/WF/Img/Btn/Delete.gif' border=0 />删除</a>";
                newRow += "</td>";

                newRow += "</tr>";

                $("#Table1 tr:last").after(newRow);
            }

            //调用公共类库的方法:执行批量主表赋值
            if (currBill != null)
                GenerFullAllCtrlsVal(currBill);

        }

        function Delete(no) {

            if (window.confirm('您确定要删除['+no+']吗？') == false)
                return;

            var en = new Entity("BP.WF.Template.BillTemplate");
            en.SetPKVal(no);
            en.Delete();

            window.location.href = window.location.href;
        }

        function Edit(no) {

            var url = "Billing.htm?FK_BillTemplate=" + no + "&FK_Node=" + GetQueryString("FK_Node");
            window.location.href = url;
        }

        function Btn_Save_Click() {

            var formData = new FormData($("#cc")[0]);

            var name = document.getElementById("TB_Name").value;
            if (name == "") {
                alert('请输入报表名称');
                return;
            }
             
            $.ajax({
                url: Handler + "?DoType=Bill_Save&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random(),
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }
                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        function Btn_New_Click() {

            document.getElementById("TB_No").value = "";
            document.getElementById("TB_Name").value = "";

        }
    </script>
</head>
<body>
    <div style="margin: 8px;">
        <form id="cc" enctype="multipart/form-data" method="post">
        <table style="width: 100%; ">
             <caption> 单据模版</caption> 
            <tr>
                <td  style=" width:15%; ">
                    编号(自动生成)
                </td>
                <td>
                    <input type="text" id="TB_No" name="TB_No" readonly="1"  style=" width:60%;"  />
                </td>
                <td style=" width:15%; " >
                    模版名称
                </td>
                <td>
                    <input type="text" id="TB_Name" name="TB_Name"  style=" width:80%;"   />
                </td>
            </tr>


            <tr>
                <td >
                   生成模版类型
                </td>
                <td>
                    <select id="DDL_BillFileType" name="DDL_BillFileType"  style=" width:60%;"  />
                </td>
                <td>
                    打开方式
                </td>
                <td>
                    <select id="DDL_BillOpenModel" name="DDL_BillOpenModel" />
                </td>
            </tr>

             <tr>
                <td>
                    是否加载二维码
                </td>
                <td>
                    <select id="DDL_QRModel" name="DDL_QRModel"   style=" width:60%;"  >
                    <option value="0">不加载二维码 </option>
                    <option value="1">加载二维码 </option>
                    </select>

                </td>
                <td>
                    模版文件:<br>符合规范的rtf格式文件.
                </td>
                <td>
                    <input id="bill" type="file" name="bill"  style=" width:60%;"  />
                </td>
            </tr>
            <tr>
             <td>
                </td>
                <td colspan="3">
                    <input type="button" id="Btn_Save" runat="server" value="保存" onclick="Btn_Save_Click()" />
                    <input type="button" id="Btn_New" runat="server" value="新建" onclick="Btn_New_Click()" />
                </td>
            </tr>
        </table>
        <br />
        <table style="width: 100%;" id="Table1">
            <caption>
                单据模版列表
            </caption>
            <tr>
                <th style="width:3%;">
                    序
                </th>
                <th  style="width:10%;">
                    编号
                </th>
                <th>
                    名称
                </th>
                 <th>
                    二维码生成方式
                </th>
                <th style="width:50%;">
                    路径
                </th>
                <th  style="width:8%;">
                    操作
                </th>
            </tr>
        </table>
        </form>
    </div>
</body>
</html>
